<template>
  <div class="swipe-preview-image">
    <!-- <p class="title">{{ name }}</p> -->
    <div class="preview-imag">
      <ImageVideo :host="host" :src="src" is-iamge />
      <div v-show="roamUrl" class="third" @click.stop="click3DHandle">
        <img src="@/assets/icon_roaming.png">
        720&deg;漫游
      </div>
    </div>
    <div v-if="list.length>1" class="bottom-contaiber">
      <Scroll horizontal stop>
        <div class="spiv-row">
          <div v-for="(l,i) in list" :key="i" :class="['spiv-col', {'active-col': index === i}]">
            <ImageVideo :host="host" :src="l" fit="cover" @click.native.stop="clickHandle(i, l)" />
          </div>
        </div>
      </Scroll>
    </div>
  </div>
</template>
<script>
import ImageVideo from '@/components/ImageVideo'
import Scroll from '@/components/Scroll'
export default {
  name: 'SwipePreviewImage',
  components: {
    ImageVideo,
    Scroll
  },
  props: {
    list: {
      type: Array,
      default: () => []
    },
    roamUrl: {
      type: String,
      default: ''
    },
    host: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      index: 0
    }
  },
  computed: {
    // name() {
    //   if (this.list.length > 0) {
    //     return this.list[this.index]
    //   } else {
    //     return ''
    //   }
    // },
    src() {
      if (this.list.length > 0) {
        return this.list[this.index]
      } else {
        return ''
      }
    }
  },
  methods: {
    clickHandle(i, item) {
      this.index = i
    },
    click3DHandle() {
      if (this.roamUrl) {
        // this.$openPage(this.roamUrl)
        this.$router.push({ name: 'Outsite', query: { src: this.roamUrl }})
      }
    }
  }
}
</script>
<style lang="less" scoped>
.swipe-preview-image{
  .title{
      color: #333;
      font-size: 14px;
      font-weight: 600;
      padding-bottom: 5px;
    }
  .preview-imag{
    position: relative;
    // max-height: 260px;
    // overflow: hidden;
    .third{
      position: absolute;
      top: 20px;
      right: 10px;
      color: #fff;
      background-color: rgba(0,0,0,.4);
      height: 24px;
      padding: 0 6px;
      line-height: 24px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      img{
        width: 14px;
        height: 14px;
        margin-right: 3px;
      }
    }
  }
  .bottom-contaiber{
    margin-top: 10px;
    .spiv-row{
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .spiv-col{
        flex: 0 0 64px;
        height: 64px;
        overflow: hidden;
        box-sizing: border-box;
      }
      .spiv-col+.spiv-col{
        margin-left: 10px;
      }
      .active-col{
        border: 1px solid #00C8B4;
      }
    }
  }
}
</style>
